// import axios from "axios"

function btnAdd() {

    location.href = '/blogs/' + 0
}

function btnEdit(id) {

    location.href = '/blogs/' + id
}

function btnDel(id) {

}

function btnSave() {
    let arrString = window.location.href.split('/')
    let id = arrString[arrString.length - 1] * 1

    let arr = document.querySelectorAll('input[name]')
    console.log(arr);

    let [i1, i2, i3, i4] = arr
    let title = i1.value
    let author = i2.value
    let publishedAt = i3.value
    let descriptions = i4.value

    let obj = {
        title, author, publishedAt, descriptions
    }
    console.log(obj);


    if (id > 0) {
        axios.put('/blogs/' + id, obj).then(res => {
            console.log(res);

            if (res.status === 200) {
                location.href = '/blogs'
            }

        })
    } else {
        axios.post('/blogs', obj).then(res => {
            if (res.status === 200) {
                location.href = '/blogs'
            }
        })
    }


}

function btnCancel() {

}